package niuke;

/**
 * description:
 * author:张腾
 * date:2021-07-03
 */

/**
 * 给定一棵二叉树，判断其是否是自身的镜像（即：是否对称）
 */
public class NC16 {
    public boolean isSymmetric (TreeNode root) {
        // write code here
        return isSame(root,root);
    }
    private boolean isSame(TreeNode left,TreeNode right){
        if (left==null&&right==null) return true;
        if ((left==null&&right!=null) || (left!=null&&right==null)) return false;
        if (left.val!=right.val) return false;
        return isSame(left.right,right.left)&&isSame(left.left,right.right);
    }
}
